package com.xu.demo.builderPattern;

import java.util.ArrayList;

// 订单建造者
public class OrderBuilder {

    private Order order;

    public OrderBuilder() {
        this.order = new Order();
    }

    public OrderBuilder setOrderNumber(String orderNumber) {
        order.setOrderNumber(orderNumber);
        return this;
    }

    public OrderBuilder addOrderItem(String productCode, int quantity) {
        if (order.getOrderItems() == null) {
            order.setOrderItems(new ArrayList<>());
        }
        order.getOrderItems().add(new OrderItem(productCode, quantity));
        return this;
    }

    public OrderBuilder setShippingAddress(String shippingAddress) {
        order.setShippingAddress(shippingAddress);
        return this;
    }

    public OrderBuilder setPaymentInfo(String paymentInfo) {
        order.setPaymentInfo(paymentInfo);
        return this;
    }

    public Order build() {
        return order;
    }
}
